package com.fand.platform.configuration.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.val;

import org.apache.commons.lang3.StringUtils;

import com.fand.dto.PaginationDto;
import com.fand.persistent.builder.ModelArgs;
import com.fand.persistent.builder.ModelBuilder;
import com.fand.persistent.builder.ModelBuilderUtils;
import com.fand.persistent.support.DaoJdbcSupport;
import com.fand.platform.configuration.dto.LanguageDto;
import com.fand.platform.configuration.dto.LanguageLoDto;

/**
 * 语言
 * 
 * @author yaoHT
 * 
 */
public class LanguageJdbcDao extends DaoJdbcSupport implements LanguageDao {

	@Override
	public int deleteLanguageBy1(LanguageDto deleteLanguage, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(deleteLanguage,
				whereEqProperties));

		return this.update("configuration/language/deleteLanguageBy1", modelBuilder.build());
	}

	@Override
	public int deleteLanguageBy1_1(LanguageDto deleteLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(deleteLanguage));

		return this.update("configuration/language/deleteLanguageBy1", modelBuilder.build());
	}

	@Override
	public int deleteLanguageByIds(LanguageDto deleteLanguage) {
		final val model = new HashMap<String, Object>();

		model.put("IDS", deleteLanguage.getIds());

		return this.update("configuration/language/deleteLanguageByIds", model);
	}

	@Override
	public int deleteLanguageLoBy1(LanguageLoDto deleteLanguageLo, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(deleteLanguageLo,
				whereEqProperties));

		return this.update("configuration/languageLo/deleteLanguageLoBy1", modelBuilder.build());
	}

	@Override
	public int insertLanguageBy1(LanguageDto insertLanguage, String... insertProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.INSERT,
				insertLanguage, insertProperties));
		return this.update("configuration/language/insertLanguageBy1", modelBuilder.build());
	}

	@Override
	public int insertLanguageBy1_1(LanguageDto insertLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.INSERT,
				insertLanguage));
		return this.update("configuration/language/insertLanguageBy1", modelBuilder.build());
	}

	@Override
	public int insertLanguageBy2(LanguageDto insertLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.INSERT,
				insertLanguage));

		return this.update("configuration/language/insertLanguageBy2", modelBuilder.build());
	}

	@Override
	public int insertLanguageLoBy1(LanguageLoDto insertLanguageLo, String... insertProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.INSERT,
				insertLanguageLo, insertProperties));
		return this.update("configuration/languageLo/insertLanguageLoBy1", modelBuilder.build());
	}

	@Override
	public PaginationDto<Map<String, Object>> paginationLanguageBy1ForMapList(LanguageDto paginationLanguage) {
		final val model = new HashMap<String, Object>();

		model.put("LOCALE_ID", paginationLanguage.getLocaleId());
		model.put("CODE", paginationLanguage.getCode());

		return this.paginationForMapList("configuration/language/selectLanguageBy2ForObject",
				"configuration/language/selectLanguageBy2ForMappedObjectList", paginationLanguage.getPaginationNo(),
				paginationLanguage.getPaginationSize(), model);
	}

	@Override
	public <R> PaginationDto<R> paginationLanguageBy1ForMappedObjectList(Class<R> mappedClass,
			LanguageDto paginationLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(paginationLanguage));

		return this.paginationForMappedObjectList(mappedClass, "configuration/language/selectLanguageBy1ForObject",
				"configuration/language/selectLanguageBy1ForMappedObjectList", paginationLanguage.getPaginationNo(),
				paginationLanguage.getPaginationSize(), modelBuilder.build());
	}

	@Override
	public <R> R selectLanguageBy1_1ForMappedObject(Class<R> mappedClass, LanguageDto selectLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage));

		return this.selectForMappedObject(mappedClass,
				"configuration/language/selectLanguageBy1ForMappedObjectList", modelBuilder.build());
	}

	@Override
	public <R> List<R> selectLanguageByCodeForMappedObjectList(Class<R> mappedClass, LanguageDto selectLanguage) {
		final val model = new HashMap<String, Object>();

		model.put("CODE", selectLanguage.getCode());

		return this.selectForMappedObjectList(mappedClass,
				"configuration/language/selectLanguageByCodeForMappedObjectList", model);
	}

	@Override
	public <R> List<R> selectLanguageBy1_1ForObjectList(Class<R> requiredType, LanguageDto selectLanguage,
			String objectId) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage));

		return this.selectForObjectList(requiredType, "configuration/language/selectLanguageBy1ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> R selectLanguageBy1ForMappedObject(Class<R> mappedClass, LanguageDto selectLanguage,
			String[] selectProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage,
				whereEqProperties));

		modelBuilder.putTrueExtend(ModelBuilder.SELECT, selectProperties);

		return this.selectForMappedObject(mappedClass,
				"configuration/language/selectLanguageBy1ForMappedObjectList", modelBuilder.build());
	}

	@Override
	public <R> List<R> selectLanguageBy1ForMappedObjectList(Class<R> mappedClass, LanguageDto selectLanguage,
			String[] selectProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage,
				whereEqProperties));

		modelBuilder.putTrueExtend(ModelBuilder.SELECT, selectProperties);

		return this.selectForMappedObjectList(mappedClass,
				"configuration/language/selectLanguageBy1ForMappedObjectList", modelBuilder.build());
	}

	@Override
	public <R> R selectLanguageBy1ForObject(Class<R> requiredType, LanguageDto selectLanguage, String objectId,
			String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage,
				whereEqProperties));

		return this.selectForObject(requiredType, "configuration/language/selectLanguageBy1ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> List<R> selectLanguageBy1ForObjectList(Class<R> requiredType, LanguageDto selectLanguage,
			String objectId, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage,
				whereEqProperties));

		return this.selectForObjectList(requiredType, "configuration/language/selectLanguageBy1ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> List<R> selectLanguageBy2ForMappedObjectList(Class<R> mappedClass, LanguageDto selectLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage));

		return this.selectForMappedObjectList(mappedClass,
				"configuration/language/selectLanguageBy2ForMappedObjectList", modelBuilder.build());
	}

	@Override
	public <R> R selectLanguageBy2ForObject(Class<R> requiredType, LanguageDto selectLanguage, String objectId) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage));

		return this.selectForObject(requiredType, "configuration/language/selectLanguageBy2ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> List<R> selectLanguageBy2ForObjectList(Class<R> requiredType, LanguageDto selectLanguage,
			String objectId) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage));

		return this.selectForObjectList(requiredType, "configuration/language/selectLanguageBy2ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> R selectLanguageByIdForMappedObject(Class<R> mappedClass, LanguageDto selectLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage, "id"));

		return this.selectForMappedObject(mappedClass,
				"configuration/language/selectLanguageBy1ForMappedObjectList", modelBuilder.build());
	}

	@Override
	public Integer selectLanguageByLocaleIdEqCodeNqIdForInteger(LanguageDto selectLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguage,
				"localeId", "code"));

		if (StringUtils.isNotBlank(selectLanguage.getId())) {
			modelBuilder.putExtend(ModelBuilder.WHERE__AND__NQ, "id", null, selectLanguage.getId());
		}

		return this.selectForObject(Integer.class, "configuration/language/selectLanguageBy1ForObject", null,
				modelBuilder.build());
	}

	@Override
	public <R> R selectLanguageLoBy1ForMappedObject(Class<R> mappedClass, LanguageLoDto selectLanguageLo,
			String[] selectProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguageLo,
				whereEqProperties));

		modelBuilder.putTrueExtend(ModelBuilder.SELECT, selectProperties);

		return this.selectForMappedObject(mappedClass,
				"configuration/languageLo/selectLanguageLoBy1ForMappedObjectList", modelBuilder.build());
	}

	@Override
	public <R> List<R> selectLanguageLoBy1ForMappedObjectList(Class<R> mappedClass, LanguageLoDto selectLanguageLo,
			String[] selectProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguageLo,
				whereEqProperties));

		modelBuilder.putTrueExtend(ModelBuilder.SELECT, selectProperties);

		return this.selectForMappedObjectList(mappedClass,
				"configuration/languageLo/selectLanguageLoBy1ForMappedObjectList", modelBuilder.build());
	}

	@Override
	public <R> R selectLanguageLoBy1ForObject(Class<R> requiredType, LanguageLoDto selectLanguageLo,
			String objectId, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguageLo,
				whereEqProperties));

		return this.selectForObject(requiredType, "configuration/languageLo/selectLanguageLoBy1ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> List<R> selectLanguageLoBy1ForObjectList(Class<R> requiredType, LanguageLoDto selectLanguageLo,
			String objectId, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(selectLanguageLo,
				whereEqProperties));

		return this.selectForObjectList(requiredType, "configuration/languageLo/selectLanguageLoBy1ForObject",
				objectId, modelBuilder.build());
	}

	@Override
	public int updateLanguageBy1(LanguageDto updateLanguage, String[] updateProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.UPDATE,
				updateLanguage, updateProperties), new ModelArgs(updateLanguage, whereEqProperties));

		return this.update("configuration/language/updateLanguageBy1", modelBuilder.build());
	}

	@Override
	public int updateLanguageByLocaleIdEqCode(LanguageDto updateLanguage, String[] updateProperties,
			LanguageDto whereLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.UPDATE,
				updateLanguage, updateProperties), new ModelArgs(whereLanguage, "localeId", "code"));

		return this.update("configuration/language/updateLanguageBy1", modelBuilder.build());
	}

	@Override
	public int updateLanguageBy2(LanguageDto updateLanguage) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(updateLanguage));

		return this.update("configuration/language/updateLanguageBy2", modelBuilder.build());
	}

	@Override
	public int updateLanguageLoBy1(LanguageLoDto updateLanguageLo, String[] updateProperties,
			String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.UPDATE,
				updateLanguageLo, updateProperties), new ModelArgs(updateLanguageLo, whereEqProperties));

		return this.update("configuration/languageLo/updateLanguageLoBy1", modelBuilder.build());
	}
}